<template>
  <div class="main-card">
    <div class="page-header">
      <h2>生活论坛</h2>
      <button class="primary-btn" @click="goPost">发布动态</button>
    </div>
    <div class="grid-layout" style="grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));">
      <div class="base-card" v-for="item in posts" :key="item.id">
        <div class="p-4">
          <div class="post-title">{{ item.title }}</div>
          <div class="post-meta text-small text-secondary">{{ item.author }} · {{ item.time }}</div>
          <div class="post-content text-secondary">{{ item.content }}</div>
          <div class="post-actions">
            <button class="action-btn" @click="item.likes++">👍 {{ item.likes }}</button>
            <button class="action-btn">💬 评论</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import '@/assets/styles/common.css'

const posts = ref([
  { id: 1, title: '新生报到攻略', author: '小明', time: '2小时前', content: '欢迎新同学，报到流程看这里...', likes: 0, comments: [] },
  { id: 2, title: '期末复习资料分享', author: '小红', time: '1天前', content: '期末复习资料已整理，欢迎自取...', likes: 0, comments: [] },
  { id: 3, title: '食堂推荐', author: '小刚', time: '3天前', content: '大家觉得哪家食堂最好吃？', likes: 0, comments: [] },
])

const router = useRouter()
function goPost() {
  router.push('/main/forum/post')
}
</script>

<style scoped>
.post-title {
  font-size: 1.08em;
  font-weight: bold;
  color: #222;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.post-meta {
  margin-bottom: 8px;
}

.post-content {
  margin-bottom: 16px;
  height: 38px;
  overflow: hidden;
}

.post-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.action-btn {
  background: #f1f5ff;
  border: none;
  border-radius: 6px;
  padding: 6px 18px;
  color: #2563eb;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn:hover {
  background: #2563eb;
  color: #fff;
}
</style>

